﻿cmake_minimum_required(VERSION 3.8)
project(QT_OpenCV_Demo LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_PREFIX_PATH C:/Qt/Qt5.14.2/5.14.2/msvc2017_64/lib/cmake)

find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Gui REQUIRED)
set(QT5_LIBS Qt5::Core Qt5::Widgets Qt5::Gui)


# --- 配置OpenCV环境 --- #
set(OpenCV_INCLUDE_DIR "C:/OpenCV/opencv/build/include")
set(OpenCV_LIB_DIR "C:/OpenCV/opencv/build/x64/vc15/lib")
# 根据程序运行模式选择使用的链接库
IF(${CMAKE_BUILD_TYPE} STREQUAL "Release")
    set(CV_LIB opencv_world430)
ELSEIF(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
    set(CV_LIB opencv_world430d)
ENDIF()

include_directories(${OpenCV_INCLUDE_DIR})
include_directories(${OpenCV_INCLUDE_DIR}/opencv2)
link_directories(${OpenCV_LIB_DIR})
link_libraries(${CV_LIB})

# --- 配置映美精相机 --- #
set(ICM_INCLUDE_DIR "D:/user/Documents/IC Imaging Control 3.5/classlib/include")
set(ICM_LIB_DIR "D:/user/Documents/IC Imaging Control 3.5/classlib/x64/debug")
set(ICM_LIB_NAME tis_udshl12d_x64)
include_directories(${ICM_INCLUDE_DIR})
link_directories(${ICM_LIB_DIR})
link_libraries(${ICM_LIB})

#查找当前文件夹中的所有源代码文件，也可以通过Set命令将所有文件设置为一个变量
FILE(GLOB SOURCE_DIR "main.cpp" "./src/*.cpp" "./src/*.h" "./src/*.ui")
# src/MainWindow.qrc必须单独写进去，不然图片会失效
add_executable(${PROJECT_NAME} ${SOURCE_DIR} ${ICM_LIB})

target_link_libraries(QT_OpenCV_Demo ${QT5_LIBS} ${CV_LIB})
# 根据程序运行模式选择可执行文件输出目录
IF(${CMAKE_BUILD_TYPE} STREQUAL "Release")
    SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
ELSEIF(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
    SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin_debug)
ENDIF()